/**
 * Created by wyy on 17-6-21.
 */


angular.module('tribalc').controller('ApproveController', [
    '$rootScope' ,'$scope', 'Api', 'RentProtocolModel',
    function ($rootScope ,$scope, Api, CompanyModel) {
    $scope.pageNum=0;
    $scope.getCompaniesList=getCompaniesList;
    $scope.isCompanyInfo = false;

    $scope.companiesList = [];
    $scope.nextSkip = null;
    $scope.prevSkip = null;
    $scope.hasMore = false;


        getCompaniesList(null,null,'desc');
        function getCompaniesList(limitSize,sortSkip,sort) {
            Api.getCompanies(limitSize,sortSkip,sort, function (result) {
                $scope.pageNum ++;
                $scope.nextSkip = result.data.nextSkip;
                $scope.hasMore = result.data.hasMore;
                if (result.data.prevSkip != null)
                {
                    var numPage = result.data.prevSkip.substr(result.data.prevSkip.length-1,1);
                    var number = parseInt(numPage) > 1 ? parseInt(numPage) - 1 : parseInt(numPage);
                    $scope.prevSkip = result.data.prevSkip.substr(0,result.data.prevSkip.length-1) + number;
                }

                setupCompaniesList(result.data.content);
                $scope.companiesList = [];
            });

        }
        function setupCompaniesList(array) {
            array.forEach(function (value) {
                Api.getCompanyDetail(value.id,function (result) {
                    $scope.companiesList.push(result.data);
                });

            });
        }


    }]);